﻿//
// Copyright (c) 2010
// by Ashish Agrawal and Chris Paterra
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Content;

namespace SimpleBlog.Components.Entities
{

	/// <summary>
	/// This is our Info class that represents columns in our data store that are associated with the SimpleBlog_Entry table.
	/// </summary>
	public class EntryInfo : ContentItem
	{

		#region Public Properties

		public int EntryId { get; set; }

		public string Title { get; set; }

		public string Summary { get; set; }

		public string BlogContent { get; set; }

		public bool AllowComments { get; set; }

		public bool Publish { get; set; }

		public int PublishedByUserId { get; set; }

		public DateTime PublishOnDate { get; set; }

		public int ModuleId { get; set; }

		public int PortalId { get; set; }

		public int CreatedByUserId { get; set; }

		public int LastModifiedByUserId { get; set; }

		////Not stored as columns
		//public int Comments { get; set; }

		public int TotalRecords { get; set; }

		//Read Only Props
		public string CreatedByUser
		{
			get
			{
				return CreatedByUserId != 0 ? DotNetNuke.Entities.Users.UserController.GetUserById(PortalId, CreatedByUserId).Username : Null.NullString;
			}
		}

		public string LastModifiedByUser {
			get
			{
				return LastModifiedByUserId != 0 ? DotNetNuke.Entities.Users.UserController.GetUserById(PortalId, LastModifiedByUserId).Username : Null.NullString;
			}
		}

		#endregion

		#region IHydratable Implementation

		/// <summary>
		/// 
		/// </summary>
		/// <param name="dr"></param>
		public override void Fill(System.Data.IDataReader dr) {
			//Call the base classes fill method to populate base class proeprties
			base.FillInternal(dr);

			EntryId = Null.SetNullInteger(dr["EntryId"]);
			Title = Null.SetNullString(dr["Title"]);
			Summary = Null.SetNullString(dr["Summary"]);
			BlogContent = Null.SetNullString(dr["BlogContent"]);
			AllowComments = Null.SetNullBoolean(dr["AllowComments"]);
			Publish = Null.SetNullBoolean(dr["Publish"]);
			PublishedByUserId = Null.SetNullInteger(dr["PublishedByUserId"]);
			PublishOnDate = Null.SetNullDateTime(dr["PublishOnDate"]);
			ModuleId = Null.SetNullInteger(dr["ModuleId"]);
			PortalId = Null.SetNullInteger(dr["PortalId"]);
			CreatedByUserId = Null.SetNullInteger(dr["CreatedByUserId"]);
			LastModifiedByUserId = Null.SetNullInteger(dr["LastModifiedByUserId"]);
			//Comments = Null.SetNullInteger(dr["Comments"]);
			TotalRecords = Null.SetNullInteger(dr["TotalRecords"]);
		}

		/// <summary>
		/// Gets and sets the Key ID
		/// </summary>
		/// <returns>An Integer</returns>
		public override int KeyID {
			get { return EntryId; }
			set { EntryId = value; }
		}

		#endregion

	}
}